@extends('backend.layouts.app')

@section('title', $title = '转账记录')

@section('breadcrumb')
    <a href="">系统设置</a>
    <a href="">集成系统</a>
    <a href="">{{$title}}</a>
@endsection

@section('content')
    <div class="layui-main">
        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
            <legend>{{$title}}</legend>
        </fieldset>
        <form class="layui-form layui-form-pane" method="GET"
              action="{{ route('player_transfer.index') }}">
            {{ csrf_field() }}
            <div class="layui-form-item">

                <div class="layui-inline">
                    <label class="layui-form-label">交易单号</label>
                    <div class="layui-input-block">
                        <input type="text" name="transferid" width="200" autocomplete="off"
                               placeholder="请输入交易单号"
                               class="layui-input" value="{{old('transferid',$params['transferid'])}}">
                    </div>
                </div>
                <div class=" layui-inline">
                    <label class="layui-form-label">交易状态</label>
                    <div class="layui-input-block">
                        <select name="status" lay-verify="" lay-search="">
                            <option value="">请选择交易状态</option>
                            <option value=1 @if($params['status']===1) selected @endif>成功</option>
                            <option value=0 @if($params['status']===0) selected @endif>失败</option>
                            <option value=-1 @if($params['status']===-1) selected @endif>未知</option>
                        </select>
                    </div>
                </div>
                <button class=" layui-btn" lay-submit="" lay-filter="demo1">提交</button>
            </div>
        </form>


        <div class="layui-form">
            @if($playerTransfers->count())
                <table class="layui-table"
                       lay-data="{id:'DeleteTable',totalRow: true,limit:{{$limit+1}}}">
                    <thead>
                    <tr>
                        <th lay-data="{type:'checkbox', fixed: 'left'}">#</th>
                        <th lay-data="{field:'id', width:80, sort: true}">id</th>
                        <th lay-data="{field:'site', width:100,  sort: true}">网站</th>
                        <th lay-data="{field:'main_game_plat_code', width:100,  sort: true}">平台编号</th>
                        <th lay-data="{field:'player',  width:150, sort: true}">玩家账号</th>
                        <th lay-data="{field:'transferid',width:200,  sort: true}">交易号</th>
                        <th lay-data="{field:'plat_transferid',  sort: true}">平台交易号</th>
                        <th lay-data="{field:'money',width:100,  sort: true}">充值分数</th>
                        <th lay-data="{field:'direction',width:100,  sort: true, }">操作类型</th>
                        <th lay-data="{field:'status',width:100,  sort: true}">转账状态</th>
                        <th lay-data="{field:'created_at', width:170, sort: true}">创建时间</th>
                        <th lay-data="{field:'updated_at', width:170, sort: true}">修改时间</th>
                        <th lay-data="{field:'cz', width:180, sort: true}">操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    @foreach($playerTransfers as $index => $playerTransfer)
                        <tr>
                            <td></td>
                            <td>{{ $playerTransfer->id }}</td>
                            <td>{{ $playerTransfer->player?($playerTransfer->player->site?$playerTransfer->player->site->username:''):''  }}</td>
                            <td>{{ $playerTransfer->plat->main_game_plat_code  }}</td>
                            <td>{{ $playerTransfer->player->username??''  }}</td>
                            <td>{{ $playerTransfer->transferid  }}</td>
                            <td>{{ $playerTransfer->plattransferid  }}</td>
                            <td>{{ $playerTransfer->money  }}</td>
                            <td>{{ $playerTransfer->getDirection()  }}</td>
                            @if($playerTransfer->status===1)
                                <td><div class="layui-bg-green" style="text-align: center">{{ $playerTransfer->getStatus() }}</div></td>
                            @elseif($playerTransfer->status===0)
                                <td><div class="layui-bg-red" style="text-align: center">{{ $playerTransfer->getStatus() }}</div></td>
                            @elseif($playerTransfer->status===-1)
                                <td><div class="layui-bg-orange" style="text-align: center">{{ $playerTransfer->getStatus() }}</div></td>
                            @endif
                            <td>{{ $playerTransfer->created_at  }}</td>
                            <td>{{ $playerTransfer->updated_at  }}</td>
                            <td>
                                @if($playerTransfer->status==-1)
                                    <a href="#" onclick="updateStatus(this,'success')" data-url="{{route('player_transfer.update_status',$playerTransfer->id)}}"
                                       class="layui-btn layui-btn-sm">确认成功</a>
                                    <a href="#" onclick="updateStatus(this,'failed')" data-url="{{route('player_transfer.update_status',$playerTransfer->id)}}"
                                       class="layui-btn layui-btn-sm layui-btn-danger">确认失败</a>
                                @endif
                            </td>
                        </tr>
                    @endforeach
                    </tbody>
                </table>
                <div id="paginate-render"></div>
            @else
                <br/>
                <blockquote class="layui-elem-quote">暂无数据!</blockquote>
            @endif

        </div>
    </div>

@endsection

@section('scripts')
    @include('backend.layouts._paginate',[ 'count' => $playerTransfers->total(), 'delBatchUrl'=>'','limit'=>$limit])

    <script type="text/javascript" src="/js/external/jquery-1.8.2.js"></script>
    <script type="text/javascript" src="/js/external/jszip.js"></script>
    <script type="text/javascript" src="/js/external/FileSaver.js"></script>
    <script type="text/javascript" src="/js/scripts/excel-gen.js"></script>
    <script>
        layui.use('laydate', function () {
            var laydate = layui.laydate;

            //日期时间选择器
            laydate.render({
                elem: '#created_at_start'
                , type: 'datetime'
            });

            laydate.render({
                elem: '#created_at_end'
                , type: 'datetime'
            });
        });
    </script>

    <script>
        $(document).ready(function () {
            excel = new ExcelGen({
                "src_id": "myTable",
                "show_header": true
            });
            $("#generate-excel").click(function () {
                excel.generate();
            });
        });


    </script>

    <script>
        var token = document.head.querySelector('meta[name="csrf-token"]');
        $.ajaxSetup({
            headers: {
                'X-CSRF-TOKEN': token.content
            }
        });
        function updateStatus(btn,status){
            var url=$(btn).data("url");
            var form = new FormData();
            form.append("status",status);
            $.ajax({
                url: url,
                data: form,
                type: 'post',
                processData:false,
                contentType:false,
                success: function (res) {
                    layer.alert(res.message, {icon: 1, time: 4000});
                    window.location.reload();
                },
                error: function (res) {
                    console.log(res);
                    layer.alert(res.message, {icon: 4, time: 4000});

                }
            });
        };    </script>
@endsection
